package com.friendsoft.web.bean;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.friendsoft.crm.bean.UserBean;
import com.friendsoft.crm.entity.User;


@SessionScoped
@ManagedBean
public class UserManagementBean {
	@EJB
	private UserBean userBean;

	private String searchString;
	private List<User> users;
	private int userCount;

	/**
	 * @return the userBean
	 */
	public UserBean getUserBean() {
		return userBean;
	}

	/**
	 * @param userBean the userBean to set
	 */
	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}

	/**
	 * @return the users
	 */
	public List<User> getUsers() {
		return users;
	}

	/**
	 * @return the userCount
	 */
	public int getUserCount() {
		return userCount;
	}

	/**
	 * @param userCount the userCount to set
	 */
	public void setUserCount(int userCount) {
		this.userCount = userCount;
	}

	/**
	 * @param users the users to set
	 */
	public void setUsers(List<User> users) {
		this.users = users;
	}

	/**
	 * @return the searchString
	 */
	public String getSearchString() {
		return searchString;
	}

	/**
	 * @param searchString the searchString to set
	 */
	public void setSearchString(String searchString) {
		this.searchString = searchString;
	}



	@PostConstruct
	public void initUsers() {
		users = userBean.getAllData();
		if(users != null && users.size() > 0) {
			userCount = users.size();
		}
	}

	public String search() {
		users = userBean.search(searchString);
		return null;
	}
}
